package com.shawn.spring.boot.jdbc.service.impl;

import com.shawn.spring.boot.jdbc.dao.UserDao;
import com.shawn.spring.boot.jdbc.entity.User;
import com.shawn.spring.boot.jdbc.service.UserService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author shawn
 * @since 2020/8/27
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

  @Autowired private UserDao dao;

  @Override
  public void insert(User user) {
    dao.insert(user);
  }

  @Override
  public void batchInsertWithJbdcTemplate(List<User> users) {
    dao.batchInsertWithList(users);
  }

  @Override
  public void batchInsertWithNamedParams(List<User> users) {
    dao.batchInsertWithNamedParams(users);
  }

  @Override
  public void batchInsertWithBatchPreparedStatementSetter(List<User> users) {
    dao.batchInsertWithBatchPreparedStatementSetter(users);
  }

  @Override
  public int insertReturnKey(User user) {
    return dao.insertReturnKey(user);
  }

  @Override
  public List<User> findAll() {
    return dao.selectAll();
  }

  @Override
  public User findById(int id) {
    return dao.selectByPrimaryKey(id);
  }

  @Override
  public List<User> findByCondition(User user) {
    return dao.selectByExample(user);
  }

  @Override
  public void modify(User user) {
    dao.update(user);
  }

  @Override
  public void remove(int id) {
    dao.delete(id);
  }

  @Override
  public int count() {
    Integer count = dao.count();
    return count == null ? 0 : count;
  }
}
